/*
* glTF 2.0 Model Render - File Open Dialog 
*
* Copyright (C) 2021 by Xuanyi Technology
*
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
#include "XyFileDialog.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vector>
#include <chrono>
#include <windows.h>
#include <commdlg.h>

std::vector<std::string> openFileDialog(char const * const aTitle, char const * const aDefaultPathAndFile)
{
    std::vector<std::string> fileList;
    char buffer[MAX_PATH];
    OPENFILENAME ofn;
    ZeroMemory(&buffer, sizeof(buffer));
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lStructSize = sizeof(ofn);
    ofn.lpstrFilter = "glTF files\0*.gltf;*.glb\0";
    ofn.lpstrFile = buffer;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrTitle = aTitle;
    ofn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR;
    if (GetOpenFileNameA(&ofn)) {
        fileList.push_back(std::string(buffer));
    }
    return fileList;
}